package com.agou.app.admin.business.menu.dao;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import org.hibernate.Query;

import com.agou.app.admin.dbconfig.bean.TSAdminMenuNavi;
import com.agou.app.admin.dbconfig.bean.VSAdminMenuNavi;
import com.agou.core.enums.EnYesNo;
import com.agou.core.ss.SSException;

public class AdminMenuDao extends IAdminMenuDao{
	//private static SSTrace ssTrace = SSTrace.getInstance(AdminMenuDao.class);
	public List<VSAdminMenuNavi> queryMenu(long naviId) throws SSException,
			SQLException, IOException {
		StringBuilder sbSql = new StringBuilder();
		sbSql.append("select t from VSAdminMenuNavi t ");
		sbSql.append(" where t.naviId = ? order by sort");
		Query query = this.getJdbcSession().createQuery(sbSql.toString());
		query.setParameter(0, naviId);
		// 对象查询条件
		@SuppressWarnings("unchecked")
		List<VSAdminMenuNavi> reList = query.list();
		return reList;
	}

	public List<TSAdminMenuNavi> queryMenuNavi() throws SSException,
			SQLException, IOException {
		StringBuilder sbSql = new StringBuilder();
		sbSql.append("select t from TSAdminMenuNavi t ");
		sbSql.append(" where t.isValid = ?");
		Query query = this.getJdbcSession().createQuery(sbSql.toString());
		query.setParameter(0, EnYesNo.Yes.getCode());
		// 对象查询条件
		@SuppressWarnings("unchecked")
		List<TSAdminMenuNavi> reList = query.list();
		return reList;
	}

	public TSAdminMenuNavi queryMenuNavi(long naviId)
			throws SSException, SQLException, IOException {
		StringBuilder sbSql = new StringBuilder();
		sbSql.append("select t from TSAdminMenuNavi t ");
		sbSql.append(" where t.naviId = ?");
		Query query = this.getJdbcSession().createQuery(sbSql.toString());
		query.setParameter(0, naviId);
		// 对象查询条件
		@SuppressWarnings("unchecked")
		List<TSAdminMenuNavi> reList = query.list();
		if(reList.size() > 0){
			return reList.get(0);
		}else{
			return null;
		}
	}

	public List<VSAdminMenuNavi> queryRootMenu(long naviId)
			throws SSException, SQLException, IOException {
		StringBuilder sbSql = new StringBuilder();
		sbSql.append("select t from VSAdminMenuNavi t ");
		sbSql.append(" where t.naviId = ? and pmenu_id =-1 order by sort");
		Query query = this.getJdbcSession().createQuery(sbSql.toString());
		query.setParameter(0, naviId);
		// 对象查询条件
		@SuppressWarnings("unchecked")
		List<VSAdminMenuNavi> reList = query.list();
		return reList;
	}
}
